//package com.hexiang.rocketmq.producer;
//
//
//import io.openmessaging.Future;
//import io.openmessaging.Message;
//import io.openmessaging.MessagingAccessPoint;
//import io.openmessaging.OMS;
//import io.openmessaging.producer.Producer;
//import io.openmessaging.producer.SendResult;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.PreDestroy;
//import java.nio.charset.StandardCharsets;
//
//@Component
//@Slf4j
//public class OMSProducer {
//
//    private static final String TOPIC_NAME = "OMS_HELLO_TOPIC";
//
//    private Producer producer;
//
//    @PostConstruct
//    public void start() {
//        MessagingAccessPoint messagingAccessPoint =
//                OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");
//        producer = messagingAccessPoint.createProducer();
//        messagingAccessPoint.startup();
//        producer.startup();
//    }
//
//    @PreDestroy
//    public void shutdown() {
//        producer.shutdown();
//    }
//
//    public void sendSyncMsg(String msgBody) {
//        Message message = producer.createBytesMessage(TOPIC_NAME, msgBody.getBytes(StandardCharsets.UTF_8));
//        SendResult sendResult = producer.send(message);
//        log.warn("sendResult " + sendResult.messageId());
//    }
//
//    public void sendOnewayMsg(String msgBody) {
//        producer.sendOneway(producer.createBytesMessage(TOPIC_NAME, msgBody.getBytes(StandardCharsets.UTF_8)));
//    }
//
//    public void sendAsyncMsg(String msgBody) {
//        Future<SendResult> result = producer.sendAsync(producer.createBytesMessage(TOPIC_NAME, msgBody.getBytes(StandardCharsets.UTF_8)));
//        result.addListener(future -> {
//            if (future.getThrowable() != null) {
//                log.error("sendResultErr " + future.getThrowable());
//            } else {
//                log.warn("sendResult " + future.get());
//            }
//        });
//    }
//}